//
//  GXthirdPartyLoginService.m
//  GaoXunTravel
//
//  Created by Jackson on 16/11/23.
//  Copyright © 2016年 May. All rights reserved.
//

#import "GXthirdPartyLoginService.h"

@implementation GXthirdPartyLoginService

//检查第三方登录
+(void)GXCheckThirdPartyLoginWithLoginType:(NSString *)loginType wechatUnionId:(NSString *)wechatUnionId qqUseId:(NSString *)qqUseId microblogIdStr:(NSString *)microblogIdStr callback:(void(^)(GXResponse *response))callback {
    NSMutableDictionary *paramsDic = [NSMutableDictionary dictionaryWithCapacity:4];
    paramsDic[@"login_type"]= loginType;
    paramsDic[@"wechat_unionid"]= wechatUnionId;
    paramsDic[@"qq_useid"]= qqUseId;
    paramsDic[@"microblog_idstr"]= microblogIdStr;
    [[GXHttpsHandle newInstance] call:HTTPMethod_POST URLString:@"login/thirdPartyIsExist" parameters:paramsDic callback:^(GXResponse *result){
//        if (result.isSuccess) {
//            if (![result.result[@"data"][@"token"] isKindOfClass:[NSNull class]]) {
//                [GXUserModel shareInstance].token = result.result[@"data"][@"sendData"][@"sendData"][@"token"];
//                [GXUserModel shareInstance].userName = result.result[@"data"][@"sendData"][@"sendData"][@"cellphone"];
//                [GXUserModel shareInstance].bakString = result.result[@"data"][@"sendData"][@"sendData"][@"bak"];
//                [GXUserModel shareInstance].isLogined = YES;
//                [GXUserModel shareInstance].ID =[NSString stringWithFormat:@"%@",[result.result[@"data"][@"sendData"][@"sendData"][@"id"] stringValue]];
//
//                [GXUserModel shareInstance].user_id =[NSString stringWithFormat:@"%@",[result.result[@"data"][@"sendData"][@"sendData"][@"id"] stringValue]];
//
//                [GXUserModel shareInstance].sessionid = result.result[@"data"][@"sendData"][@"sid"];
//                [GXUserModel shareInstance].headUrl = [NSString stringWithFormat:@"%@%@%@",GX_IMAGE_URL,result.result[@"data"][@"sendData"][@"sendData"][@"save_path"],result.result[@"data"][@"sendData"][@"sendData"][@"automatic_file_name"]];
//                [GXUserModel shareInstance].nikName = result.result[@"data"][@"sendData"][@"sendData"][@"nick_name"];
//                [GXUserModel shareInstance].sex =[NSString stringWithFormat:@"%d",[result.result[@"data"][@"sendData"][@"sendData"][@"sex"] intValue]] ;
//                [GXUserModel shareInstance].address =[NSString stringWithFormat:@"%@ %@",result.result[@"data"][@"sendData"][@"sendData"][@"province"],result.result[@"data"][@"sendData"][@"sendData"][@"city"]] ;
//                [GXUserModel shareInstance].email = result.result[@"data"][@"sendData"][@"sendData"][@"email"];
//                [GXUserModel shareInstance].job = result.result[@"data"][@"sendData"][@"sendData"][@"job"];
//                [GXUserModel shareInstance].user_id = [NSString stringWithFormat:@"%d",[result.result[@"data"][@"sendData"][@"os_info"][@"user_id"]intValue]];
//                [GXUserModel shareInstance].cellphone = result.result[@"data"][@"sendData"][@"sendData"][@"cellphone"];
//                [GXUserModel shareInstance].remark = result.result[@"data"][@"sendData"][@"sendData"][@"remark"];
//                [GXUserModel shareInstance].registration = result.result[@"data"][@"sendData"][@"sendData"][@"registration"];
//                NSLog(@"headurl:%@",[GXUserModel shareInstance].headUrl);
//                NSLog(@"username:%@",[GXUserModel shareInstance].userName);
//                NSLog(@"bakString:%@",[GXUserModel shareInstance].bakString);
//                NSLog(@"cellphone:%@",[GXUserModel shareInstance].cellphone);
//                NSLog(@"nikName:%@",[GXUserModel shareInstance].nikName);
//                NSLog(@"sessionid:%@",[GXUserModel shareInstance].sessionid);
//
//            }else{
//                [GXUserModel shareInstance].isLogined = NO;
//
//            }
//            [GXUserModel saveLoginUserInfo];
//
//        }
        if (result.isSuccess) {
            //RCToken
            [GXUserModel shareInstance].RCToken = [NSString stringWithFormat:@"%@",result.result[@"data"][@"sendData"][@"sendData"][@"token"]];
            //isLogin
            [GXUserModel shareInstance].isLogined = YES;
            //token
            [GXUserModel shareInstance].token = [NSString stringWithFormat:@"%@",result.result[@"data"][@"sendData"][@"sendData"][@"token"]];
            //user_id
            [GXUserModel shareInstance].user_id = [NSString stringWithFormat:@"%@",result.result[@"data"][@"sendData"][@"os_info"][@"user_id"]];
            //ID
            [GXUserModel shareInstance].ID = [NSString stringWithFormat:@"%@",[result.result[@"data"][@"sendData"][@"sendData"][@"id"] stringValue]];
            //sessionid
            [GXUserModel shareInstance].sessionid = [NSString stringWithFormat:@"%@",result.result[@"data"][@"sendData"][@"sid"]];
            //userName
            [GXUserModel shareInstance].userName = [NSString stringWithFormat:@"%@",result.result[@"data"][@"sendData"][@"sendData"][@"cellphone"]];
            //password
            //nikName
            [GXUserModel shareInstance].nikName = [NSString stringWithFormat:@"%@",result.result[@"data"][@"sendData"][@"sendData"][@"nick_name"]];
            //sex
            [GXUserModel shareInstance].sex =[NSString stringWithFormat:@"%d",[result.result[@"data"][@"sendData"][@"sendData"][@"sex"] intValue]] ;
            //job
            [GXUserModel shareInstance].job = [NSString stringWithFormat:@"%@",result.result[@"data"][@"sendData"][@"sendData"][@"job"]];
            //email
            [GXUserModel shareInstance].email = [NSString stringWithFormat:@"%@",result.result[@"data"][@"sendData"][@"sendData"][@"email"]];
            //address
            [GXUserModel shareInstance].address =[NSString stringWithFormat:@"%@ %@",result.result[@"data"][@"sendData"][@"sendData"][@"province"],result.result[@"data"][@"sendData"][@"sendData"][@"city"]];
            //hobby
            //birthday
            //cellPhone
            [GXUserModel shareInstance].cellphone = [NSString stringWithFormat:@"%@",result.result[@"data"][@"sendData"][@"sendData"][@"cellphone"]];
            //remark
            [GXUserModel shareInstance].remark = [NSString stringWithFormat:@"%@",result.result[@"data"][@"sendData"][@"sendData"][@"remark"]];
            //headUrl
            [GXUserModel shareInstance].headUrl = [NSString stringWithFormat:@"%@%@%@",GX_IMAGE_URL,result.result[@"data"][@"sendData"][@"sendData"][@"save_path"],result.result[@"data"][@"sendData"][@"sendData"][@"automatic_file_name"]];
            //fileUserIcon
            //province
            //city
            //headImageData
            //fileIdArr
            //uidString
            //bakString
            [GXUserModel shareInstance].bakString = [NSString stringWithFormat:@"%@",result.result[@"data"][@"sendData"][@"sendData"][@"bak"]];
            //loginType
            //        [GXUserModel shareInstance].loginType = loginType;
            //registration
            [GXUserModel shareInstance].bakString = [NSString stringWithFormat:@"%@",result.result[@"data"][@"sendData"][@"sendData"][@"registration"]];
            //role_num
            [GXUserModel shareInstance].role_num = [NSString stringWithFormat:@"%@",result.result[@"data"][@"sendData"][@"sendData"][@"role_num"]];
            //customerGroupId
            [GXUserModel shareInstance].customerGroupId = [NSString stringWithFormat:@"%@",result.result[@"data"][@"sendData"][@"sendData"][@"customer_group_id"]];
            [GXUserModel saveLoginUserInfo];
        }
        if (callback) {
            callback(result);
        }
        
    }];

}

//第三方登录
+(void)GXThirdPartyLoginWithType:(NSString *)loginType wechatUnionId:(NSString *)wechatUnionId qqUseId:(NSString *)qqUseId microblogIdStr:(NSString *)microblogIdStr cellphone:(NSString *)cellphone loginName:(NSString *)loginName loginPwd:(NSString *)loginPwd nick_name:(NSString *)nick_name registration:(NSString *)registration signIn:(NSString *)signIn callback:(void(^)(GXResponse *response))callback {

    NSMutableDictionary *paramsDic = [NSMutableDictionary dictionaryWithCapacity:4];
    paramsDic[@"login_type"]= loginType;
    paramsDic[@"wechat_unionid"]= wechatUnionId;
    paramsDic[@"qq_useid"]= qqUseId;
    paramsDic[@"microblog_idstr"]= microblogIdStr;
    paramsDic[@"cellphone"]= cellphone;
    paramsDic[@"login_name"]= loginName;
    paramsDic[@"login_pwd"]= loginPwd;
    paramsDic[@"registration"]= registration;
    paramsDic[@"signIn"]= signIn;
    paramsDic[@"nick_name"] = nick_name;
    [[GXHttpsHandle newInstance] call:HTTPMethod_POST URLString:@"login/thirdPartyLoginIn" parameters:paramsDic callback:^(GXResponse *result){
        if (result.isSuccess) {
            //  [GXUserModel shareInstance].isLogined = YES;
            if (![result.result[@"data"][@"token"] isKindOfClass:[NSNull class]]) {
                [GXUserModel shareInstance].token = result.result[@"data"][@"sendData"][@"sendData"][@"token"];
                [GXUserModel shareInstance].userName = result.result[@"data"][@"sendData"][@"sendData"][@"cellphone"];
                [GXUserModel shareInstance].bakString = result.result[@"data"][@"sendData"][@"sendData"][@"bak"];
                [GXUserModel shareInstance].isLogined = YES;
                
                [GXUserModel shareInstance].ID =[NSString stringWithFormat:@"%@",[result.result[@"data"][@"sendData"][@"sendData"][@"id"] stringValue]];
                
                [GXUserModel shareInstance].user_id =[NSString stringWithFormat:@"%@",[result.result[@"data"][@"sendData"][@"sendData"][@"id"] stringValue]];

                [GXUserModel shareInstance].sessionid = result.result[@"data"][@"sendData"][@"sid"];
                [GXUserModel shareInstance].headUrl = [NSString stringWithFormat:@"%@%@%@",GX_IMAGE_URL,result.result[@"data"][@"sendData"][@"sendData"][@"save_path"],result.result[@"data"][@"sendData"][@"sendData"][@"automatic_file_name"]];
                [GXUserModel shareInstance].nikName = result.result[@"data"][@"sendData"][@"sendData"][@"nick_name"];
                [GXUserModel shareInstance].sex =[NSString stringWithFormat:@"%d",[result.result[@"data"][@"sendData"][@"sendData"][@"sex"] intValue]] ;
                [GXUserModel shareInstance].address =[NSString stringWithFormat:@"%@ %@",result.result[@"data"][@"sendData"][@"sendData"][@"province"],result.result[@"data"][@"sendData"][@"sendData"][@"city"]] ;
                [GXUserModel shareInstance].email = result.result[@"data"][@"sendData"][@"sendData"][@"email"];
                [GXUserModel shareInstance].job = result.result[@"data"][@"sendData"][@"sendData"][@"job"];
                [GXUserModel shareInstance].user_id = [NSString stringWithFormat:@"%d",[result.result[@"data"][@"sendData"][@"os_info"][@"user_id"]intValue]];
                [GXUserModel shareInstance].cellphone = result.result[@"data"][@"sendData"][@"sendData"][@"cellphone"];
                [GXUserModel shareInstance].registration = result.result[@"data"][@"sendData"][@"sendData"][@"registration"];
                [GXUserModel shareInstance].remark = result.result[@"data"][@"sendData"][@"sendData"][@"remark"];
                NSLog(@"headurl:%@",[GXUserModel shareInstance].headUrl);
                NSLog(@"username:%@",[GXUserModel shareInstance].userName);
                NSLog(@"bakString:%@",[GXUserModel shareInstance].bakString);
                NSLog(@"cellphone:%@",[GXUserModel shareInstance].cellphone);
                NSLog(@"nikName:%@",[GXUserModel shareInstance].nikName);
                NSLog(@"sessionid:%@",[GXUserModel shareInstance].sessionid);

            }else{
                [GXUserModel shareInstance].isLogined = NO;
                
            }
            [GXUserModel saveLoginUserInfo];
            
        }
        if (callback) {
            callback(result);
        }
        
    }];

}


//绑定
+(void)GXThirdPartyBindingWithType:(NSString *)loginType wechatUnionId:(NSString *)wechatUnionId qqUseId:(NSString *)qqUseId microblogIdStr:(NSString *)microblogIdStr cellphone:(NSString *)cellphone loginName:(NSString *)loginName loginPwd:(NSString *)loginPwd    callback:(void(^)(GXResponse *response))callback {


    NSMutableDictionary *paramsDic = [NSMutableDictionary dictionaryWithCapacity:4];
    paramsDic[@"login_type"]= loginType;
    paramsDic[@"wechat_unionid"]= wechatUnionId;
    paramsDic[@"qq_useid"]= qqUseId;
    paramsDic[@"microblog_idstr"]= microblogIdStr;
    paramsDic[@"cellphone"]= cellphone;
    paramsDic[@"login_name"]= loginName;
    paramsDic[@"login_pwd"]= loginPwd;
    [[GXHttpsHandle newInstance] call:HTTPMethod_POST URLString:@"login/thirdPartyLoginIn" parameters:paramsDic callback:^(GXResponse *result){
        if (result.isSuccess) {
            //  [GXUserModel shareInstance].isLogined = YES;
            if (![result.result[@"data"][@"token"] isKindOfClass:[NSNull class]]) {
                [GXUserModel shareInstance].token = result.result[@"data"][@"sendData"][@"sendData"][@"token"];
                [GXUserModel shareInstance].userName = result.result[@"data"][@"sendData"][@"sendData"][@"cellphone"];
                [GXUserModel shareInstance].bakString = result.result[@"data"][@"sendData"][@"sendData"][@"bak"];
                [GXUserModel shareInstance].isLogined = YES;
                
                [GXUserModel shareInstance].ID =[NSString stringWithFormat:@"%@",[result.result[@"data"][@"sendData"][@"sendData"][@"id"] stringValue]];
                
                [GXUserModel shareInstance].user_id =[NSString stringWithFormat:@"%@",[result.result[@"data"][@"sendData"][@"sendData"][@"id"] stringValue]];
                
                [GXUserModel shareInstance].sessionid = result.result[@"data"][@"sendData"][@"sid"];
                [GXUserModel shareInstance].headUrl = [NSString stringWithFormat:@"%@%@%@",GX_IMAGE_URL,result.result[@"data"][@"sendData"][@"sendData"][@"save_path"],result.result[@"data"][@"sendData"][@"sendData"][@"automatic_file_name"]];
                [GXUserModel shareInstance].nikName = result.result[@"data"][@"sendData"][@"sendData"][@"nick_name"];
                [GXUserModel shareInstance].sex =[NSString stringWithFormat:@"%d",[result.result[@"data"][@"sendData"][@"sendData"][@"sex"] intValue]] ;
                [GXUserModel shareInstance].address =[NSString stringWithFormat:@"%@ %@",result.result[@"data"][@"sendData"][@"sendData"][@"province"],result.result[@"data"][@"sendData"][@"sendData"][@"city"]] ;
                [GXUserModel shareInstance].email = result.result[@"data"][@"sendData"][@"sendData"][@"email"];
                [GXUserModel shareInstance].job = result.result[@"data"][@"sendData"][@"sendData"][@"job"];
                [GXUserModel shareInstance].user_id = [NSString stringWithFormat:@"%d",[result.result[@"data"][@"sendData"][@"os_info"][@"user_id"]intValue]];
                [GXUserModel shareInstance].cellphone = result.result[@"data"][@"sendData"][@"sendData"][@"cellphone"];
                [GXUserModel shareInstance].remark = result.result[@"data"][@"sendData"][@"sendData"][@"remark"];
                [GXUserModel shareInstance].registration = result.result[@"data"][@"sendData"][@"sendData"][@"registration"];
                NSLog(@"headurl:%@",[GXUserModel shareInstance].headUrl);
                NSLog(@"username:%@",[GXUserModel shareInstance].userName);
                NSLog(@"bakString:%@",[GXUserModel shareInstance].bakString);
                NSLog(@"cellphone:%@",[GXUserModel shareInstance].cellphone);
                NSLog(@"nikName:%@",[GXUserModel shareInstance].nikName);
                NSLog(@"sessionid:%@",[GXUserModel shareInstance].sessionid);
                
            }else{
                [GXUserModel shareInstance].isLogined = NO;
                
            }
            [GXUserModel saveLoginUserInfo];
            
        }
        if (callback) {
            callback(result);
        }
        
    }];

}
@end
